/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.aqlm.data;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.rainbow.annotation.xml.ChildNode;
import org.rainbow.annotation.xml.NodeText;

/**
 *
 * @author hironaga
 */
public class RsvUDO{

    private static DateFormat timestampFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SS");
    private static DateFormat filenameFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSS");

    //----予約内容 Begin
    @NodeText( elementName="name" )
    private String name;

    @NodeText( elementName="yomi" )
    private String yomi;

    @NodeText( elementName="tel" )
    private String tel;

    @NodeText( elementName="email" )
    private String email;

    @NodeText( elementName="times" )
    private int times;

    private String timesName;

    @ChildNode( elementName="reserve" )
    private List<RsvDateUDO> reserve;

    @ChildNode( elementName="course" )
    private CourseUDO course;

    @NodeText( elementName="memo" )
    private String memo;

    @ChildNode( elementName="receipt" )
    private RsvDateUDO receipt;

    //予約登録日
    @NodeText( elementName="regist-date" )
    private Date registDate;

    //予約認証日
    @NodeText( elementName="reflect-date" )
    private Date reflectDate;

    //最終更新日
    @NodeText( elementName="last-update" )
    private Date lastUpdate;
    //---予約内容 End


    public String getRegistDateOnFileFormat(){
        return filenameFormat.format(this.registDate);
    }

    public String getTimesName() {
        return timesName;
    }

    private void setTimesName(int times) {
        if(times == 0){
            this.timesName = RsvBeanTimesName.FIRST.toString();
        }
        else if(times == 1){
            this.timesName = RsvBeanTimesName.OVER_SECOND.toString();
        }
    }
    
    @Override
    public String toString(){
        StringBuilder rsvDateString = new StringBuilder();
        for(RsvDateUDO rsvDate : reserve){
            rsvDateString.append(rsvDate.toString());
        }

    return //super.toString() +
            "name:" + this.name +
            ", yomi:" + this.yomi +
            ", tel:" + this.tel + 
            ", email:" + this.email +
            ", times:" + this.times +
            ", timesName:" + this.timesName +
            ", course:" + this.course +
            ", reserve:" + rsvDateString.toString() +
            ", memo:" + this.memo +
            ", receipt:" + this.receipt +
            ", registDate:" + this.registDate +
            ", reflectDate:" + this.reflectDate +
            ", lastUpdate:" + this.lastUpdate;
    }

    private enum RsvBeanTimesName{
        FIRST("初めて"),
        OVER_SECOND("２回目以上");

        private String name;
        private RsvBeanTimesName(String name){
            this.name = name;
        }
        @Override
        public String toString() {
            return this.name;
        }
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getLastUpdate() {
        return lastUpdate;
    }

    public void setLastUpdateString(String lastUpdateStr) {
        this.lastUpdate = UDOUtils.getOnDateType(lastUpdateStr, timestampFormat);
    }

    public String getMemo() {
        return memo;
    }

    public void setMemo(String memo) {
        this.memo = memo;
    }

    public CourseUDO getCourse() {
        return course;
    }

    public void setCourse(CourseUDO course) {
        this.course = course;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public RsvDateUDO getReceipt() {
        return receipt;
    }

    public void setReceipt(RsvDateUDO receipt) {
        this.receipt = receipt;
    }

    public Date getReflectDate() {
        return reflectDate;
    }

    public void setReflectDateString(String reflectDateStr) {
        this.reflectDate = UDOUtils.getOnDateType(reflectDateStr, timestampFormat);
    }

    public Date getRegistDate() {
        return registDate;
    }

    public void setRegistDateString(String registDateStr) {
        this.registDate = UDOUtils.getOnDateType(registDateStr, timestampFormat);
    }

    public List<RsvDateUDO> getReserve() {
        return reserve;
    }

    public void setReserve(List<RsvDateUDO> reserve) {
        this.reserve = reserve;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public int getTimes() {
        return times;
    }

    public void setTimes(int times) {
        this.times = times;
        setTimesName(times);
    }

    public String getYomi() {
        return yomi;
    }

    public void setYomi(String yomi) {
        this.yomi = yomi;
    }

    public void setLastUpdate(Date lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    public void setReflectDate(Date reflectDate) {
        this.reflectDate = reflectDate;
    }

    public void setRegistDate(Date registDate) {
        this.registDate = registDate;
    }
    
}
